﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

// Token: 0x02000073 RID: 115
public class DemoCamera : MonoBehaviour
{
	// Token: 0x1700003F RID: 63
	// (get) Token: 0x060003A0 RID: 928 RVA: 0x00017098 File Offset: 0x00015298
	public float Distance
	{
		get
		{
			return this.distance;
		}
	}

	// Token: 0x17000040 RID: 64
	// (get) Token: 0x060003A1 RID: 929 RVA: 0x000170A0 File Offset: 0x000152A0
	public Vector3 Focus
	{
		get
		{
			return this.focus;
		}
	}

	// Token: 0x17000041 RID: 65
	// (get) Token: 0x060003A2 RID: 930 RVA: 0x000170A8 File Offset: 0x000152A8
	public Vector3 Rotation
	{
		get
		{
			return this.rotate;
		}
	}

	// Token: 0x17000042 RID: 66
	// (get) Token: 0x060003A3 RID: 931 RVA: 0x000170B0 File Offset: 0x000152B0
	public float FOV
	{
		get
		{
			return base.GetComponent<Camera>().fieldOfView;
		}
	}

	// Token: 0x060003A4 RID: 932 RVA: 0x000170C0 File Offset: 0x000152C0
	private void Awake()
	{
		this.viewCollider = base.gameObject.AddComponent<CapsuleCollider>();
		this.viewCollider.radius = 0.05f;
		this.viewCollider.isTrigger = true;
		this.viewCollider.direction = 2;
		this.buttonState[0] = DemoCamera.ButtonState.NO;
		this.buttonState[2] = DemoCamera.ButtonState.NO;
		this.buttonState[1] = DemoCamera.ButtonState.NO;
	}

	// Token: 0x060003A5 RID: 933 RVA: 0x00017124 File Offset: 0x00015324
	private void Start()
	{
	}

	// Token: 0x060003A6 RID: 934 RVA: 0x00017128 File Offset: 0x00015328
	private void LateUpdate()
	{
		if (base.GetComponent<Camera>() == null)
		{
			return;
		}
		float num = Input.GetAxis("Mouse X") * this.mouseSensitivity;
		float num2 = Input.GetAxis("Mouse Y") * this.mouseSensitivity;
		if (Input.GetKey(KeyCode.LeftShift))
		{
			num *= 3f;
			num2 *= 3f;
		}
		if (Input.GetKey(KeyCode.LeftControl))
		{
			num *= 0.25f;
			num2 *= 0.25f;
		}
		bool flag = false;
		bool flag2 = EventSystem.current && EventSystem.current.IsPointerOverGameObject();
		this.ButtonStateCheck();
		if (!flag2 && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)))
		{
			this.dragging = true;
		}
		else if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2))
		{
			this.dragging = false;
		}
		if (this.dragging)
		{
			if (Input.GetMouseButton(0) && Input.GetMouseButton(1))
			{
				flag = true;
				if (this.centerDragMove == DemoCamera.CenterDragMove.XY)
				{
					this.Translate(new Vector3(num, 0f, num2), true);
				}
				else
				{
					this.Translate(new Vector3(num, num2, 0f), true);
				}
			}
			else if (Input.GetMouseButton(0))
			{
				if (this.mouseRevX)
				{
					num *= -1f;
				}
				if (this.mouseRevY)
				{
					num2 *= -1f;
				}
				flag = true;
				this.Rotate(new Vector3(-num2, num, 0f));
			}
			else if (Input.GetMouseButton(2))
			{
				flag = true;
				if (this.centerDragMove == DemoCamera.CenterDragMove.XY)
				{
					this.Translate(new Vector3(num, num2, 0f), true);
				}
				else
				{
					this.Translate(new Vector3(num, 0f, num2), false);
				}
			}
			else if (Input.GetMouseButton(1))
			{
				flag = true;
				this.distance += num * this.translateSpeed;
				this.distance = Mathf.Clamp(this.distance, 0.01f, 100f);
				this.Translate(new Vector3(0f, num2, 0f), false);
			}
			if (this.dragLock)
			{
			}
		}
		flag |= this.KeyInput();
		Vector3 point = this.nowCenterOffset;
		if (this.centerDisOffset != 0f)
		{
			point.x *= this.centerDisOffset * this.distance;
			point.y *= this.centerDisOffset * this.distance;
			point.z *= this.centerDisOffset * this.distance;
		}
		Quaternion rotation = Quaternion.Euler(this.rotate);
		base.transform.rotation = rotation;
		Vector3 b = rotation * point;
		Vector3 b2 = rotation * (Vector3.back * this.distance);
		base.transform.position = this.focus + b + b2;
		this.viewCollider.height = this.distance;
		this.viewCollider.center = Vector3.forward * this.distance * 0.5f;
		if (!this.showTgt || !this.target || flag)
		{
		}
	}

	// Token: 0x060003A7 RID: 935 RVA: 0x000174A4 File Offset: 0x000156A4
	private void OnGUI()
	{
	}

	// Token: 0x060003A8 RID: 936 RVA: 0x000174A8 File Offset: 0x000156A8
	private void ButtonStateCheck()
	{
		for (int i = 0; i < 3; i++)
		{
			if (Input.GetMouseButtonDown(i))
			{
				this.buttonState[i] = DemoCamera.ButtonState.DOWN;
			}
			else if (Input.GetMouseButtonUp(i))
			{
				this.buttonState[i] = DemoCamera.ButtonState.UP;
			}
			else if (Input.GetMouseButton(i))
			{
				this.buttonState[i] = DemoCamera.ButtonState.HOLD;
			}
			else
			{
				this.buttonState[i] = DemoCamera.ButtonState.NO;
			}
		}
	}

	// Token: 0x060003A9 RID: 937 RVA: 0x0001751C File Offset: 0x0001571C
	public void Set(Vector3 focus, Vector3 rotate, float distance, float parse = 0f)
	{
		this.focus = focus;
		this.rotate = rotate;
		this.distance = distance;
		if (parse > 0f)
		{
			base.GetComponent<Camera>().fieldOfView = parse;
		}
	}

	// Token: 0x060003AA RID: 938 RVA: 0x0001754C File Offset: 0x0001574C
	public void SetFocus(Vector3 focus)
	{
		this.focus = focus;
	}

	// Token: 0x060003AB RID: 939 RVA: 0x00017558 File Offset: 0x00015758
	private void Translate(Vector3 vec, bool localTranslate)
	{
		if (localTranslate)
		{
			Quaternion rotation = Quaternion.Euler(this.rotate);
			this.focus += rotation * (vec * this.translateSpeed);
		}
		else
		{
			Quaternion rotation2 = Quaternion.Euler(0f, this.rotate.y, 0f);
			this.focus += rotation2 * (vec * this.translateSpeed);
		}
	}

	// Token: 0x060003AC RID: 940 RVA: 0x000175E0 File Offset: 0x000157E0
	private void Rotate(Vector3 angles)
	{
		this.rotate += angles * this.rotateSpeed;
	}

	// Token: 0x060003AD RID: 941 RVA: 0x00017600 File Offset: 0x00015800
	private bool KeyInput_Value(ref float val, float move, KeyCode addKey, KeyCode subKey)
	{
		if (Input.GetKey(addKey))
		{
			this.KeyInput_Accel(ref val, move);
			return true;
		}
		if (Input.GetKey(subKey))
		{
			this.KeyInput_Accel(ref val, -move);
			return true;
		}
		this.KeyInput_Brake(ref val, move);
		return false;
	}

	// Token: 0x060003AE RID: 942 RVA: 0x00017638 File Offset: 0x00015838
	private bool KeyInputDown_Value(ref float val, float move, KeyCode addKey, KeyCode subKey)
	{
		if (Input.GetKeyDown(addKey))
		{
			val += move;
			return true;
		}
		if (Input.GetKeyDown(subKey))
		{
			val -= move;
			return true;
		}
		return false;
	}

	// Token: 0x060003AF RID: 943 RVA: 0x00017664 File Offset: 0x00015864
	private void KeyInput_Accel(ref float val, float move)
	{
		val += move * this.keyAccel * Time.deltaTime;
		if (move > 0f)
		{
			val = Mathf.Min(val, move);
		}
		else
		{
			val = Mathf.Max(val, move);
		}
	}

	// Token: 0x060003B0 RID: 944 RVA: 0x000176A0 File Offset: 0x000158A0
	private void KeyInput_Brake(ref float val, float move)
	{
		float a = Mathf.Abs(val) - move * this.keyBrake * Time.deltaTime;
		if (val > 0f)
		{
			val = Mathf.Max(a, 0f);
		}
		else
		{
			val = -Mathf.Max(a, 0f);
		}
	}

	// Token: 0x060003B1 RID: 945 RVA: 0x000176F0 File Offset: 0x000158F0
	private bool KeyInput()
	{
		bool flag = false;
		KeyCode addKey = this.keyRevX ? KeyCode.Keypad4 : KeyCode.Keypad6;
		KeyCode subKey = this.keyRevX ? KeyCode.Keypad6 : KeyCode.Keypad4;
		KeyCode addKey2 = this.keyRevY ? KeyCode.Keypad8 : KeyCode.Keypad2;
		KeyCode subKey2 = this.keyRevY ? KeyCode.Keypad2 : KeyCode.Keypad8;
		flag |= this.KeyInput_Value(ref this.keyRotSpeed.y, this.keySensitivity, addKey, subKey);
		flag |= this.KeyInput_Value(ref this.keyRotSpeed.x, this.keySensitivity, addKey2, subKey2);
		flag |= this.KeyInput_Value(ref this.keyMovSpeed.x, this.keySensitivity, KeyCode.RightArrow, KeyCode.LeftArrow);
		flag |= this.KeyInput_Value(ref this.keyMovSpeed.z, this.keySensitivity, KeyCode.UpArrow, KeyCode.DownArrow);
		flag |= this.KeyInput_Value(ref this.keyMovSpeed.y, this.keySensitivity, KeyCode.PageUp, KeyCode.PageDown);
		flag |= this.KeyInput_Value(ref this.keyDisSpeed, this.keySensitivity * 0.02f, KeyCode.End, KeyCode.Home);
		if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
		{
			bool flag2 = this.KeyInputDown_Value(ref this.rotate.z, 45f, KeyCode.Period, KeyCode.Backslash);
			flag = (flag || flag2);
			if (flag2)
			{
				this.keyRotSpeed.z = 0f;
			}
		}
		else
		{
			flag |= this.KeyInput_Value(ref this.keyRotSpeed.z, this.keySensitivity * 0.5f, KeyCode.Period, KeyCode.Backslash);
		}
		if (Input.GetKey(KeyCode.Slash))
		{
			this.rotate.z = 0f;
			this.keyRotSpeed.z = 0f;
			flag = true;
		}
		flag |= this.KeyInput_Value(ref this.keyFovSpeed, this.keySensitivity * 0.2f, KeyCode.RightBracket, KeyCode.Equals);
		if (Input.GetKey(KeyCode.Semicolon))
		{
			base.GetComponent<Camera>().fieldOfView = this.defParse;
			this.keyFovSpeed = 0f;
			flag = true;
		}
		if (this.keyRotSpeed.magnitude != 0f)
		{
			this.Rotate(this.keyRotSpeed);
		}
		if (this.keyMovSpeed.magnitude != 0f)
		{
			Vector3 vec = new Vector3(this.keyMovSpeed.x, this.keyMovSpeed.y, 0f);
			Vector3 vec2 = new Vector3(0f, 0f, this.keyMovSpeed.z);
			this.Translate(vec, false);
			this.Translate(vec2, true);
			flag = true;
		}
		if (this.keyFovSpeed != 0f)
		{
			base.GetComponent<Camera>().fieldOfView += this.keyFovSpeed;
			base.GetComponent<Camera>().fieldOfView = Mathf.Clamp(base.GetComponent<Camera>().fieldOfView, 0.01f, 90f);
		}
		if (this.keyDisSpeed != 0f)
		{
			this.distance += this.keyDisSpeed;
		}
		return flag;
	}

	// Token: 0x060003B2 RID: 946 RVA: 0x00017A28 File Offset: 0x00015C28
	public Vector3 GetDirection()
	{
		return base.transform.rotation * Vector3.forward;
	}

	// Token: 0x060003B3 RID: 947 RVA: 0x00017A40 File Offset: 0x00015C40
	public Vector3 GetTargetPos()
	{
		return this.target.transform.position;
	}

	// Token: 0x0400032E RID: 814
	[SerializeField]
	private float mouseSensitivity = 3f;

	// Token: 0x0400032F RID: 815
	[SerializeField]
	private float keySensitivity = 3f;

	// Token: 0x04000330 RID: 816
	[SerializeField]
	private float rotateSpeed = 1f;

	// Token: 0x04000331 RID: 817
	[SerializeField]
	private float translateSpeed = 1f;

	// Token: 0x04000332 RID: 818
	[SerializeField]
	private float keyAccel = 5f;

	// Token: 0x04000333 RID: 819
	[SerializeField]
	private float keyBrake = 5f;

	// Token: 0x04000334 RID: 820
	[SerializeField]
	private Vector3 focus = new Vector3(0f, 0f, 0f);

	// Token: 0x04000335 RID: 821
	[SerializeField]
	private Vector3 rotate = new Vector3(0f, 0f, 0f);

	// Token: 0x04000336 RID: 822
	[SerializeField]
	private float distance = 1.5f;

	// Token: 0x04000337 RID: 823
	[SerializeField]
	private float defParse = 45f;

	// Token: 0x04000338 RID: 824
	[SerializeField]
	private bool mouseRevY;

	// Token: 0x04000339 RID: 825
	[SerializeField]
	private bool mouseRevX;

	// Token: 0x0400033A RID: 826
	[SerializeField]
	private bool keyRevY;

	// Token: 0x0400033B RID: 827
	[SerializeField]
	private bool keyRevX;

	// Token: 0x0400033C RID: 828
	[SerializeField]
	private Transform target;

	// Token: 0x0400033D RID: 829
	[SerializeField]
	private bool showTgt = true;

	// Token: 0x0400033E RID: 830
	[SerializeField]
	private bool dragLock = true;

	// Token: 0x0400033F RID: 831
	[SerializeField]
	private DemoCamera.CenterDragMove centerDragMove;

	// Token: 0x04000340 RID: 832
	private Vector3 nowCenterOffset = Vector3.zero;

	// Token: 0x04000341 RID: 833
	public Vector3 setCenterOffset = Vector3.zero;

	// Token: 0x04000342 RID: 834
	[SerializeField]
	private float centerDisOffset;

	// Token: 0x04000343 RID: 835
	private Vector3 keyRotSpeed = new Vector3(0f, 0f, 0f);

	// Token: 0x04000344 RID: 836
	private Vector3 keyMovSpeed = new Vector3(0f, 0f, 0f);

	// Token: 0x04000345 RID: 837
	private float keyDisSpeed;

	// Token: 0x04000346 RID: 838
	private float keyFovSpeed;

	// Token: 0x04000347 RID: 839
	private CapsuleCollider viewCollider;

	// Token: 0x04000348 RID: 840
	private DemoCamera.ButtonState[] buttonState = new DemoCamera.ButtonState[3];

	// Token: 0x04000349 RID: 841
	private bool dragging;

	// Token: 0x02000074 RID: 116
	private enum MouseButton
	{
		// Token: 0x0400034B RID: 843
		MB_LEFT,
		// Token: 0x0400034C RID: 844
		MB_RIGHT,
		// Token: 0x0400034D RID: 845
		MB_MIDDLE,
		// Token: 0x0400034E RID: 846
		NUM
	}

	// Token: 0x02000075 RID: 117
	private enum ButtonState
	{
		// Token: 0x04000350 RID: 848
		NO,
		// Token: 0x04000351 RID: 849
		DOWN,
		// Token: 0x04000352 RID: 850
		HOLD,
		// Token: 0x04000353 RID: 851
		UP
	}

	// Token: 0x02000076 RID: 118
	public enum CenterDragMove
	{
		// Token: 0x04000355 RID: 853
		XY,
		// Token: 0x04000356 RID: 854
		XZ
	}
}
